//Generates balance table (Table 1)

clear all

use "$data/incFinalMonthlyTehsil", clear

drop if monyr >575 //drop observations from before study period
drop if dist=="swa" //drop observations from SWA

//Generate variables for summary statistics
collapse (mean) incidents totCas peace mo pdens population male female education health agriculture wheatcrop registration cf percent pop pp validvotes100k rejectvotes100k totalvotes100k rgisteredvotes100k numberofseats, by(tehsiln tehsil distn dist)

//Labels for table
label variable incidents "Incidents"
label variable totCas "Casualties"
label variable peace "Peace Deal"
label variable mo "Military Operations"
label variable pdens "Pdens"
label variable population "Population per Tehsil"
label variable male "Male per Tehsil" 
label variable female "Female per Tehsil"
label variable education "Education Spending (in Rs) per Tehsil"
label variable health "Health Spending (in Rs) per Tehsil"
label variable agriculture "Agriculture Spending (in Rs) per Tehsil"
label variable wheatcrop "Wheat Produce per Tehsil"
label variable registration "Annual Registration per Tehsil"
label variable cf "Total Registered Population per Tehsil"
label variable percent "Prop Registered Population per Tehsil"
label variable validvotes100k "Valid Votes Cast per 100k"
label variable rejectvotes100k "Reject Votes Cast per 100k"
label variable rgisteredvotes100k "Registered Voters Cast per 100k"

g  dp=0
replace dp=1 if dist=="nwa"

//Generate summary statistics
estpost sum incidents totCas peace mo population male female education health agriculture wheatcrop registration cf percent validvotes100k rejectvotes100k rgisteredvotes100k if dp==1
matrix meanf1=e(mean)
matrix list meanf1
estpost sum incidents totCas peace mo population male female education health agriculture wheatcrop registration cf percent validvotes100k rejectvotes100k rgisteredvotes100k if dp==0
matrix meanf0=e(mean)
matrix list meanf0
estpost ttest incidents totCas peace mo population male female education health agriculture wheatcrop registration cf percent validvotes100k rejectvotes100k rgisteredvotes100k, by(dp)
eststo imp
estadd matrix meanf1
estadd matrix meanf0

//Output Table 1
esttab using "$tables/balancetest.csv", replace label noobs nonum cells("meanf1(fmt(2)) meanf0(fmt(2)) b(fmt(2))") collabels("Mean (Tehsils NWA)" "Mean (Other Tehsils)" "Difference") title(Balance Table Pre-Drone Program \label{tab:baltpredp})
esttab using "$tables/balancetest.tex", replace label noobs nonum cells("meanf1(fmt(2)) meanf0(fmt(2)) b(fmt(2))") collabels("Mean (Tehsils NWA)" "Mean (Other Tehsils)" "Difference") title(Balance Table Pre-Drone Program \label{tab:baltpredp}) ///
addn("This table displays pre-program sample means for a number of variables both inside and outside North Waziristan" /// 
"Agency, as well as differences in these means between these two regions. For the first four variables, we present means" /// 
"of tehsil-month-level varaibles from 2003-2007. The remaining variables are measured at the district-level at a single" ///
"pre-program time period and we present district-level means weighted by the number of tehsils per district.") substitute(\math $ \gt >)
